package com.example.base_model.weight

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.ripple
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
 * @author 宾有为
 * @date 2025/3/21 17:07
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：
 **/

@Composable
fun RoundedRectButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    height: Dp = 48.dp,
    cornerRadius: Dp = 10.dp,
    elevation: Dp = 6.dp,
    textColor: Color = Color.White,
    gradient: Brush = Brush.linearGradient(
        colors = listOf(Color(0xFF6A8DFF), Color(0xFF5CC8FF))
    ),
    icon: ImageVector? = null,
    iconContentDescription: String? = null,
) {
    val shape = RoundedCornerShape(cornerRadius)

    Row(
        modifier = modifier
            .height(height)
            .clip(shape)
            .shadow(elevation, shape, clip = false)
            .background(brush = gradient, shape = shape)
            .clickable(
                interactionSource = MutableInteractionSource(),
                indication = ripple(bounded = true, color = Color.White),
                onClick = onClick
            )
            .padding(horizontal = 16.dp),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.Center
    ) {
        if (icon != null) {
            Icon(
                imageVector = icon,
                contentDescription = iconContentDescription,
                tint = textColor,
                modifier = Modifier.padding(end = 8.dp).sizeIn(maxHeight = 24.dp, maxWidth = 24.dp),
            )
        }
        Text(
            text = text,
            color = textColor,
            fontSize = 16.sp,
            fontWeight = FontWeight.SemiBold
        )
    }
}